<template>
  <section>
    <div class="custorm--modelbox graphicbtns-edit">
      <!-- <upload-model ref="upload" :saveChangeEvt="uploadSaveChange" :uploadType="uploadConfig.type" :config="uploadConfig"></upload-model> -->
      <!-- <choose-path ref="choosepath" :changeEvt="chooseUrl" :tabType="tabType"></choose-path> -->
      <renohome-right-nav :custormItemData="custormItemData" @rightNavChange="rightNavChange"></renohome-right-nav>
      <section v-if="nrActive">
        <div class="edit-form-item">
          <div class="form-label">颜色选择</div>
          <div class="stylebox flex-row flex-align-c ivu-color-picker"><span style="margin-right:13px;">文字</span>
            <el-color-picker class="ivu-input" v-model="custormItemData.style.textcolor" size="mini"></el-color-picker>
            <span class="ivu-input">{{custormItemData.style.textcolor}}</span>
          </div>
          <div class="stylebox flex-row flex-align-c ivu-color-picker"><span style="margin-right:13px;">背景</span>
            <el-color-picker class="ivu-input" v-model="custormItemData.style.bgcolor" size="mini"></el-color-picker>
            <span class="ivu-input">{{custormItemData.style.bgcolor}}</span>
          </div>
        </div>
        <div class="edit-form-item">
          <div class="form-label mb-20">按钮形状</div>
          <el-radio-group
            v-model="custormItemData.style.btnstyle"
            class="flex-row mar-15"
          >
            <el-radio label="1">直角</el-radio>
            <el-radio label="2">圆角</el-radio>
            <el-radio label="3">圆</el-radio>
          </el-radio-group>
        </div>
        <!-- <div class="es-form-item" v-if="custormItemData.style.display==1">
          <div class="form-label mb-20">按钮形状</div>
          <div class="item-inner">
            <label class="button-shape ">
              <div class="button-shape-square" @click="custormItemData.style.btnstyle = 1" v-bind:class="{active:custormItemData.style.btnstyle==1}"></div>
            </label>
            <label class="button-shape ">
              <div class="button-shape-arc" @click="custormItemData.style.btnstyle = 2" v-bind:class="{active:custormItemData.style.btnstyle==2}"></div>
            </label>
            <label class="button-shape ">
              <div class="button-shape-circle" @click="custormItemData.style.btnstyle = 3" v-bind:class="{active:custormItemData.style.btnstyle==3}"></div>
            </label>
          </div>
        </div> -->

        <div class="edit-form-item">
          <div class="form-label mb-20">每行数量</div>
          <el-radio-group v-model="custormItemData.params.rowtype" class="flex-row mar-15">
            <el-radio label="1">3个</el-radio>
            <el-radio label="2">4个</el-radio>
            <el-radio label="3">5个</el-radio>
          </el-radio-group>
        </div>
        <div class="es-form-item" style="margin-top:-20px;">
          <span>图片尺寸要求：100*100像素</span>
          <div style="padding-top: 10px;">
            <div class="item" draggable="false" v-for="(item, index) in custormItemData.data" :key="index">
              <i class="el-icon-circle-close  delete-child" @click="delItemList({data:custormItemData.data, index})"></i>
              <div v-if="custormItemData.style.display=='1'" class="item-inner"><span class="labeltext">图片</span>
                <div typetext="图片" show="0" class="small" style="align-self: start;">
                  <div class="uploadSource solid"><i class="delete ivu-icon iconfont icon-input_clear" style="font-size: 16px;"></i>
                    <div class="img" @click="uploadtoggle(index,'image')" :style="{'background-image':`url(${getPath(item.thumb.file_path)})`,'height':'50px','background-repeat':'no-repeat','background-size':'cover','background-position':'50%'}"></div>
                  </div>
                </div>
              </div>
              <!-- <div
                v-if="custormItemData.style.display=='2'"
                class="item-inner "
              ><span class="labeltext">图标</span>
                <div
                  show="0"
                  class="small"
                  style="align-self: start;"
                >
                  <div
                    class="uploadSource solid"
                    @click="pathtoggle(index,'icon')"
                  >
                    <i
                      :class="[item.edit.icon]"
                      style="font-size: 30px;"
                    ></i>
                  </div>
                </div>
              </div> -->
              <div class="item-inner ">
                <span class="labeltext">文字</span>
                <el-input v-model="item.title" maxlength="5" size="mini" style="width: 0;flex-grow: 1;"></el-input>
              </div>
              <div class="item-inner ">
                <span class="labeltext">链接</span>
                <div class="readonly-div" @click="uploadtoggle(index,'link')">
                  <div class="readonly ivu-input-wrapper ivu-input-wrapper-default ivu-input-type">
                    <input autocomplete="off" spellcheck="false" type="text" placeholder="请选择链接" readonly="readonly" class="ivu-input ivu-input-default" :value="typeof item.link === 'string' ? item.link : item.link.path">
                  </div> <i class="icon icon-fujian readonly-icon" style="left: 12px;margin-top:-3px;"></i>
                </div>
              </div>
            </div>

          </div>
          <div class="goodscol-add" @click="addItemList({data:custormItemData.data,max:10,itemCopy:{title: '按钮文字',link: '',thumb: {file_path: 'default_btn1.png'},icon: 'icon icon-qiehuan'}})"><i class="el-icon-plus"></i> 添加
            {{custormItemData.data.length}}/10</div>
        </div>
      </section>
      <section v-if="fgActive">
        <div class="es-form-item">
          <div class="item-inner block"><label class="button-img block" @click="changePattern(1)" v-bind:class="{active:custormItemData.style.display==1}">
              <div class="es-menu-group col-4 circle">
                <div class="es-icon-col">
                  <div class="icon"><img :src="getPath('default_btn1.png')"></div>
                  <div class="text" style="color: rgb(51, 51, 51);">按钮</div>
                </div>
                <div class="es-icon-col">
                  <div class="icon"><img :src="getPath('default_btn1.png')"></div>
                  <div class="text" style="color: rgb(51, 51, 51);">按钮</div>
                </div>
                <div class="es-icon-col">
                  <div class="icon"><img :src="getPath('default_btn1.png')"></div>
                  <div class="text" style="color: rgb(51, 51, 51);">按钮</div>
                </div>
                <div class="es-icon-col">
                  <div class="icon"><img :src="getPath('default_btn1.png')"></div>
                  <div class="text" style="color: rgb(51, 51, 51);">按钮</div>
                </div>
              </div>
            </label></div>
          <div class="item-inner block"><label class="button-img block" @click="changePattern(2)" v-bind:class="{active:custormItemData.style.display==2}">
              <div class="es-icon-group col-4">
                <div class="es-icon-col">
                  <div class="icon"><i class="iconfont icon-qiehuan"></i> <span class="mark">8</span></div>
                  <div class="text line-hide">按钮</div>
                </div>
                <div class="es-icon-col">
                  <div class="icon"><i class="iconfont icon-qiehuan"></i>
                  </div>
                  <div class="text line-hide">按钮</div>
                </div>
                <div class="es-icon-col">
                  <div class="icon"><i class="iconfont icon-qiehuan"></i>
                  </div>
                  <div class="text line-hide">按钮</div>
                </div>
                <div class="es-icon-col">
                  <div class="icon"><i class="iconfont icon-qiehuan"></i>
                  </div>
                  <div class="text line-hide">按钮</div>
                </div>
              </div>
            </label></div>
        </div>
      </section>
    </div>
  </section>
</template>

<script>
// import uploadModel from "../../components/upload";
//  import choosePath from "../../components/choosePath";
import defaultConfig from './utils/editConfig'
export default {
  mixins: [defaultConfig.mixins],
  props: {
    defaultConfig: {
      type: Object,
      default: function() {
        return defaultConfig
      }
    }
  },
  data() {
    return {
      tabType: ['home', 'ather'],
      imgCurrent: -1,
      uploadConfig: {
        ismore: false,
        auto: false,
        type: ['image'],
        isShowList: false
      }
    }
  },
  components: {
    // uploadModel,
    // choosePath
  },
  methods: {
    uploadFileCallBack(files) {
      const { key } = files
      if (key === 'ChooseLink') {
        const { currentRow: [file_path], displayData: [custorm] } = files
        if (this.imgCurrent !== -1 && file_path) {
          this.custormItemData.data[this.imgCurrent]['link'] = file_path
        } else {
          if (custorm) {
            this.custormItemData.data[this.imgCurrent]['link'] = custorm
          } else {
            this.$message.error('请选择链接~!')
          }
        }
      } else {
        const { displayData: [file_path] } = files
        if (this.imgCurrent !== -1 && file_path) {
          this.custormItemData.data[this.imgCurrent]['thumb'] = file_path
        }
      }
    },
    uploadtoggle(index, type) {
      var data = this.custormItemData.data[index]['link']
      this.output({ type, params: { editKey: this.custormItemData.key }, data })
      this.imgCurrent = index
    }
  }
}
</script>

<style lang="scss" scoped>
.custorm--modelbox.graphicbtns-edit {
  //列表开始
  .es-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;

    .uploadSource {
      background: #fff;
      cursor: pointer;
    }

    .uploadSource {
      width: 50px;
      height: 50px;
      line-height: 50px;
      margin-right: 0;
      border: 1px dashed #ededed;
      text-align: center;
      color: #dad9d9;
      background-size: 100% 100%;
      background-repeat: no-repeat;
      float: left;
      position: relative;
    }
  }

  .es-form-item:last-child {
    border-bottom: 0;
  }

  .es-form-item .item-inner {
    margin-top: 8px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .es-form-item .item-inner:first-of-type {
    margin-top: 0;
  }

  .es-form-item .button-img {
    width: 32px;
    height: 32px;
    margin-right: 20px;
    cursor: pointer;
    border-radius: 4px;
    box-sizing: border-box;
    line-height: 36px;
    text-align: center;
    border: 1px solid transparent;
  }

  .es-form-item .button-img.block {
    width: 100%;
    position: relative;
    min-height: 32px;
    height: auto;
    padding: 10px;
    text-align: left;
  }

  .es-form-item .button-img.active {
    border-color: #fb6638 !important;
  }

  .es-form-item .alignC {
    text-align: center;
  }

  .es-form-item .item {
    background: #f6f7f9;
    padding: 10px 20px 10px 10px;
    border: 1px solid #eee;
    color: #999;
    position: relative;
    margin-bottom: 20px;
  }

  .es-form-item .labeltext {
    width: 40px;
    text-align: right;
    padding-right: 8px;
    color: #666;
  }

  .es-form-item .item-inner .readonly-div {
    position: relative;
    flex-grow: 1;
  }

  .ivu-input-wrapper {
    display: inline-block;
    width: 100%;
    position: relative;
    vertical-align: middle;
    line-height: normal;
  }

  .es-form-item .item-inner .readonly-div .readonly input {
    background: #e8effc;
    border: 0;
    padding-left: 18px;
    cursor: pointer;
    box-sizing: border-box;
  }

  .es-form-item .item-inner .readonly-div .readonly-icon {
    position: absolute;
    top: 5px;
    left: 12px;
  }

  .es-form-item .item .delete-child {
    position: absolute;
    right: 4px;
    top: 0;
    cursor: pointer;
    font-size: 14px;
  }

  //列表结束

  //风格开始
  .es-menu-group {
    padding-bottom: 18px;
    background: #fff;
    overflow: hidden;
  }

  .es-menu-group .es-icon-col {
    float: left;
    text-align: center;
    margin-top: 18px;
  }

  .es-menu-group.col-4 .es-icon-col {
    width: 25%;
  }

  .es-icon-group {
    padding-bottom: 18px;
    background: #fff;
    overflow: hidden;
  }

  .es-icon-group.col-4 .es-icon-col {
    width: 25%;
  }

  .es-icon-group .es-icon-col {
    float: left;
    text-align: center;
    margin-top: 18px;
  }

  .es-icon-col .text {
    font-size: 10px;
  }

  .es-menu-group .es-icon-col .text {
    margin-top: 4px;
    font-size: 10px;
    color: #999;
    line-height: 1.5;
  }

  .es-menu-group.circle img {
    border-radius: 50%;
  }

  .es-menu-group .icon img {
    height: 40px;
    width: 40px;
    display: inline-block !important;
  }

  .button-img.block img {
    max-width: 100%;
    max-height: 100%;
    display: block;
  }

  .es-icon-group .icon {
    position: relative;
    height: 36px;
  }

  .es-icon-group .icon i {
    font-size: 24px;
  }

  .es-icon-group .icon .mark {
    position: absolute;
    width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 50%;
    color: #fff;
    left: 50%;
    top: 2px;
    background: #f55;
  }

  //风格结束
  .color-input {
    width: 56px;
    cursor: pointer;
    border-radius: 2px;
  }

  .color-input + span {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    line-height: 26px;
    width: 56px;
    height: 26px;
    margin-left: 10px;
    background: #f1f1f1;
    border-color: #dfdfdf;
    cursor: pointer;
    border-radius: 2px;
    border: 1px solid #dfdfdf;
    text-align: center;
  }
}
</style>
